package co.edu;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class Datos extends SQLiteOpenHelper {

	String sqlCrear;
	
	public Datos(Context Contexto, String Nombre, CursorFactory Cursor,
			int Version) {
		super(Contexto, Nombre, Cursor, Version);
		
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		sqlCrear = "CREATE TABLE dbIns (insRegs INTEGER NOT NULL)";
		db.execSQL(sqlCrear);		
		sqlCrear = "CREATE TABLE niveles (id_niv INTEGER PRIMARY KEY NOT NULL, nom_niv TEXT NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE prog_acad (id_prog TEXT PRIMARY KEY NOT NULL, nom_prog TEXT NOT NULL, niv_prog INTEGER NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE grp_ref (id_grp INTEGER PRIMARY KEY NOT NULL, nom_grp TEXT NOT NULL, id_prog TEXT NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE modulos (id_mod INTEGER NOT NULL, nom_mod TEXT NOT NULL, grp_ref INTEGER NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE tipo_preg (id_tipo INTEGER PRIMARY KEY NOT NULL, nomb_tipo TEXT NULL, desc_tipo TEXT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE preguntas (id_prg INTEGER PRIMARY KEY NOT NULL, enu_prg BLOB NOT NULL, rt1_prg TEXT NOT NULL, rt2_prg TEXT NOT NULL, rt3_prg TEXT NOT NULL, rt4_prg TEXT NOT NULL, clv_prg INTEGER NOT NULL, typ_prg INTEGER NOT NULL, mod_prg INTEGER NOT NULL, fe_prg DATE NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE respuestas (id_prg INTEGER NOT NULL, usr_rta TEXT NOT NULL, clv_prg INTEGER NOT NULL, mod_prg INTEGER NOT NULL, fec_rta DATE NOT NULL)";
		db.execSQL(sqlCrear);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int versionAnt, int versionNew) {
		
		//db.execSQL(sqlCrear);
		db.execSQL("DROP TABLE IF EXIST niveles");
		db.execSQL("DROP TABLE IF EXIST prog_acad");
		db.execSQL("DROP TABLE IF EXIST grp_ref");
		db.execSQL("DROP TABLE IF EXIST modulos");
		db.execSQL("DROP TABLE IF EXIST tipo_preg");
		db.execSQL("DROP TABLE IF EXIST preguntas");
		db.execSQL("DROP TABLE IF EXIST respuestas");
		db.execSQL("DROP TABLE IF EXIST dbIns");
		
		sqlCrear = "CREATE TABLE dbIns (insRegs INTEGER NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE niveles (id_niv INTEGER PRIMARY KEY NOT NULL, nom_niv TEXT NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE prog_acad (id_prog TEXT PRIMARY KEY NOT NULL, nom_prog TEXT NOT NULL, niv_prog INTEGER NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE grp_ref (id_grp INTEGER PRIMARY KEY NOT NULL, nom_grp TEXT NOT NULL, id_prog TEXT NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE modulos (id_mod INTEGER PRIMARY KEY NOT NULL, nom_mod TEXT NOT NULL, grp_ref INTEGER NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE tipo_preg (id_tipo INTEGER PRIMARY KEY NOT NULL, nomb_tipo TEXT NULL, desc_tipo TEXT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE preguntas (id_prg INTEGER PRIMARY KEY NOT NULL, enu_prg BLOB NOT NULL, rt1_prg TEXT NOT NULL, rt2_prg TEXT NOT NULL, rt3_prg TEXT NOT NULL, rt4_prg TEXT NOT NULL, clv_prg INTEGER NOT NULL, typ_prg INTEGER NOT NULL, mod_prg INTEGER NOT NULL, fe_prg DATE NOT NULL)";
		db.execSQL(sqlCrear);
		sqlCrear = "CREATE TABLE respuestas (id_prg INTEGER NOT NULL, usr_rta TEXT NOT NULL, clv_prg INTEGER NOT NULL, mod_prg INTEGER NOT NULL, fec_rta DATE NOT NULL)";
		db.execSQL(sqlCrear);
	}
	

}
